# https://blog.csdn.net/weixin_39935257/article/details/110542782?utm_term=python%E9%9A%8F%E6%9C%BA%E7%94%9F%E6%88%90%E4%B8%80%E4%B8%AA%E8%8B%B1%E6%96%87&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-0-110542782&spm=3001.4430
# name的值三到5个小写字母且保证唯一，age的值的取值范围为大于10小于60的整数，sex取值为0、1、2中的一个,city固定为深圳,province固定为广东，ext字段中boost字段取值为0、1、2、3中的一个，其余固定不变。
import random
import copy
import string

mydict = {
  "name": "Tom",
  "age": "18",
  "sex": 1,
  "city": "深圳",
  "province": "广东",
  "ext": {
    "type": "dynamic",
    "inner_hits": {},
    "score_mode": "avg",
    "min_children": 0,
    "max_children": 25555,
    "ignore_unmapped": False,
    "boost": 1
  }
}

# users = []
# names = []
# # 随机生成英文名字
# for n in range(0, 10):
#     user = copy.deepcopy(mydict)
#     name = ''.join(random.sample(string.ascii_lowercase, random.randint(3, 5)))
#     while name in names:
#         name = random.sample(string.ascii_lowercase, random.randint(3, 5))
#     names.append(name)
#     user['name'] = name
#     user['age'] = random.randint(11, 59)
#     user['sex'] = random.randint(0, 2)
#     user['ext']['boost'] = random.randint(0, 3)
#     users.append(user)
#     n += 1
#
# for u in users:
#     print(u)
# print(users)

# 定义一个创建数据的函数
def creat():
    users = []
    names = []
    # 深度拷贝模板
    user = copy.deepcopy(mydict)
    # 随机生成名字
    name = ''.join(random.sample(string.ascii_lowercase, random.randint(3, 5)))
    # 当名称与之前创建的一致，则重新生成，保证名称唯一性
    while name in names:
         name = random.sample(string.ascii_lowercase, random.randint(3, 5))
    names.append(name)
    user['name'] = name
    # 随机生成年龄
    user['age'] = random.randint(11, 59)
    # 随机生成性别
    user['sex'] = random.randint(0, 2)
    # 随机生成boost的值
    user['ext']['boost'] = random.randint(0, 3)
    users.append(user)
    print(users)

# 循环10次
for n in range(0,10):
    creat()